<template>
  <div v-show="item.status === 'error'" class="item-error">
    <img src="@/assets/error-robot.png" width="32" height="32" />
    <p v-if="isSensitiveCode(item.errorCode)" class="error-text">
      抱歉，您的内容里
      <span v-if="sensitiveHits">【{{ sensitiveHits }}】</span>
      触发了安全审查机制，请您更换其他表述后重试哦
    </p>
    <p v-else-if="item.errorCode === 1015" class="error-text">
      抱歉，您今日对话次数已达到平台上限，请明天再继续哦！
    </p>
    <error-message :telport="telport" :text="item.errorInfo&&item.errorInfo.msg" v-else-if="item.errorCode === 1009"/>
    <p v-else-if="isDifyRetry(item.errorCode)" class="error-text">
      抱歉，模型响应遇到一点问题，您可以重新试试
    </p>
    <p v-else-if="item.errorCode === 4002" class="error-text">
      尊敬的VIP，您本月{{
        item.model && item.model.toUpperCase() || "模型"
      }}权益次数已用完，请于次月购买日（含）起再使用
    </p>
    <error-message :telport="telport" v-else />
  </div>
</template>

<script>
import ErrorMessage from '@/components/error-message/index.vue'
import { isSensitiveCode, isDifyRetry } from '@/utils/index'
export default {
  name: '',
  components: {
    ErrorMessage
  },
  data () {
    return {
    }
  },
  props: {
    item: {
      type: Object,
      default: () => {}
    },
    telport: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    sensitiveHits () {
      const data = this.item.errorInfo
      if (data?.code !== 1004) return ''
      const res = data.data
      if (!res) return ''
      const words = new Set()
      res.forEach((v) => {
        // eslint-disable-next-line no-unused-expressions
        v.hits?.forEach((w) => {
          w.words.forEach((v1) => words.add(v1))
        })
      })
      return [...words].join('；')
    }
  },
  mounted () {
    // console.log('error', this.item)
  },
  methods: {
    isSensitiveCode,
    isDifyRetry
  }
}
</script>

<style lang="scss" scoped>
.item-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  .error-icon {
    flex: 0 0 20px;
    color: $color-white;
  }
  .error-text {
    font-size: $font-size-base;
    flex: 1 1 100%;
    padding: 0;
    line-height: 32px;
    font-size: 14px;
    span {
      color: $color-primary1;
    }
  }
}
</style>
